/**
 * Created by 叶子 on 2017/7/30.
 */
import * as type from './type';
import * as http from '../axios/index';

const requestData = category => ({
    type: type.REQUEST_DATA,
    category
});
export const receiveData = (data, category) => ({
    type: type.RECEIVE_DATA,
    data,
    category
});
/**
 * 请求数据调用方法
 * @param funcName      请求接口的函数名
 * @param params        请求接口的参数
 */
export const fetchData = ({funcName, params, stateName}) => dispatch => {
    !stateName && (stateName = funcName);
    dispatch(requestData(stateName));
    return http[funcName](params).then(res => dispatch(receiveData(res, stateName)));
};

/**
 * author heshengjin
 * date 2017-10-10
 */
export const countData = (data, category) => ({
    type: type.COUNT_DATA,
    data,
    category
});


/**
 * @author heshengjin
 * @date 2017-10-14
 * 直接在reduce里面初始化，对比COUNT_DATA在获取的时候初始化
 * 不要category
 * @type {string}
 */
export const countDataInit = (data) => ({
    type: type.COUNT_DATA_INIT,
    data
});